const CryptoJS = require("crypto-js");

const key = CryptoJS.enc.Utf8.parse('base@uinnova');

// const {encrypt, decrypt} = require('./rsa-demo');

/**
 * 加密
 */
const encode = function (str) {
    return CryptoJS.DES.encrypt(str, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    }).toString();
};

/**
 * 解密
 */
const decode = function (str) {
    return CryptoJS.DES.decrypt(str, key, {
        mode: CryptoJS.mode.ECB,
        padding: CryptoJS.pad.Pkcs7
    }).toString(CryptoJS.enc.Utf8);
};

var json = {
    real_groups: [
        'jw', 'huwei',
        'test1', 'test2',
        'test3', 'test4',
        'test5', 'test6'
    ],
    name: 'jw',
    groups: [
        'jw', 'huwei',
        'test1', 'test2',
        'test3', 'test4',
        'test5', 'test6',
        '$all', '$authenticated',
        '@all', '@authenticated',
        'all', 'jw',
        'huwei', 'test1',
        'test2', 'test3',
        'test4', 'test5',
        'test6',
        'jw', 'huwei',
        'test1', 'test2',
        'test3', 'test4',
        'test5', 'test6',
        '$all', '$authenticated',
        '@all', '@authenticated',
        'all', 'jw',
        'huwei', 'test1',
        'test2', 'test3',
        'test4', 'test5',
        'test6',
        'jw', 'huwei',
        'test1', 'test2',
        'test3', 'test4',
        'test5', 'test6',
        '$all', '$authenticated',
        '@all', '@authenticated',
        'all', 'jw',
        'huwei', 'test1',
        'test2', 'test3',
        'test4', 'test5',
        'test6'
    ]
};


(async function(){
    // const data = encode(JSON.stringify(json));
    const data = encode('qdownload kiss');
    console.log(data);
    console.log(data.length);
    
    console.log(decode(data));


    // const data2 = await encrypt(JSON.stringify(json));
    // const data2 = await encrypt(data);
    // // console.log(data2);
    // console.log(data2.length);
    
    // console.log(await decrypt(data2));
})()

